package com.nowcoder.arithmetic;

/**
 * User: Ruijie Date: 2016/9/1
 */
public class ConvertSortedArrayToBinarySearchTree {
    private static class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        public TreeNode(int val){
            this.val=val;
        }
    }
    public static TreeNode sortedArrayToBST(int[] num) {
        if (num==null||num.length==0){
            return null;
        }
        return process(num,0,num.length-1);
    }

    private static TreeNode process(int[] num, int left, int right) {
        if(left<=right){
            int mid=(left+right)>>1;
            TreeNode node=new TreeNode(num[mid]);
            node.left=process(num,left,mid-1);
            node.right=process(num,mid+1,right);
            return node;
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(4>>2);
    }
}
